package com.rran.study.designpattern.structural.proxy;

import org.springframework.cglib.proxy.MethodInterceptor;
import org.springframework.cglib.proxy.MethodProxy;

import java.lang.reflect.Method;

/**
 * @author yy
 * @Type CglibDynamicProxy.java
 * @Desc
 * @date 2020/7/27 15:06
 */
public class CglibDynamicProxy  implements MethodInterceptor {

    @Override
    public Object intercept(Object o, Method method, Object[] objects, MethodProxy methodProxy) throws Throwable {
        before();
        Object result = methodProxy.invokeSuper(o, objects);
        after();
        return result;
    }

    private void before() {
        System.out.println("方法执行前");
    }

    private void after() {
        System.out.println("方法执行后");
    }
}
